package o;

import java.io.IOException;

final class agn {
    private long ʻ = -9223372036854775807L;
    private long ʽ = -9223372036854775807L;
    private final anc ˊ = new anc();
    private boolean ˋ;
    private boolean ˎ;
    private final anq ˏ = new anq(0);
    private boolean ॱ;
    private long ᐝ = -9223372036854775807L;

    agn() {
    }

    public boolean ˏ() {
        return this.ˎ;
    }

    public anq ˎ() {
        return this.ˏ;
    }

    public int ˎ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        if (!this.ॱ) {
            return ˋ(o_adv, o_adz);
        }
        if (this.ʻ == -9223372036854775807L) {
            return ˊ(o_adv);
        }
        if (!this.ˋ) {
            return ˊ(o_adv, o_adz);
        }
        if (this.ᐝ == -9223372036854775807L) {
            return ˊ(o_adv);
        }
        this.ʽ = this.ˏ.ˏ(this.ʻ) - this.ˏ.ˏ(this.ᐝ);
        return ˊ(o_adv);
    }

    public long ॱ() {
        return this.ʽ;
    }

    public static long ˋ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        if (o_anc.ˊ() < 9) {
            return -9223372036854775807L;
        }
        byte[] bArr = new byte[9];
        o_anc.ˎ(bArr, 0, bArr.length);
        o_anc.ˋ(ˋ);
        if (ॱ(bArr)) {
            return ˎ(bArr);
        }
        return -9223372036854775807L;
    }

    private int ˊ(adv o_adv) {
        this.ˊ.ˋ(anr.ʽ);
        this.ˎ = true;
        o_adv.ˏ();
        return 0;
    }

    private int ˊ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        int min = (int) Math.min(20000, o_adv.ॱ());
        if (o_adv.ˊ() != ((long) null)) {
            o_adz.ˊ = (long) null;
            return 1;
        }
        this.ˊ.ˏ(min);
        o_adv.ˏ();
        o_adv.ˎ(this.ˊ.ˏ, 0, min);
        this.ᐝ = ˊ(this.ˊ);
        this.ˋ = true;
        return 0;
    }

    private long ˊ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        for (int i = ˋ; i < ॱ - 3; i++) {
            if (ˎ(o_anc.ˏ, i) == 442) {
                o_anc.ˋ(i + 4);
                long ˋ2 = ˋ(o_anc);
                if (ˋ2 != -9223372036854775807L) {
                    return ˋ2;
                }
            }
        }
        return -9223372036854775807L;
    }

    private int ˋ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        long ॱ = o_adv.ॱ();
        int min = (int) Math.min(20000, ॱ);
        ॱ -= (long) min;
        if (o_adv.ˊ() != ॱ) {
            o_adz.ˊ = ॱ;
            return 1;
        }
        this.ˊ.ˏ(min);
        o_adv.ˏ();
        o_adv.ˎ(this.ˊ.ˏ, 0, min);
        this.ʻ = ˏ(this.ˊ);
        this.ॱ = true;
        return 0;
    }

    private long ˏ(anc o_anc) {
        int ˋ = o_anc.ˋ();
        for (int ॱ = o_anc.ॱ() - 4; ॱ >= ˋ; ॱ--) {
            if (ˎ(o_anc.ˏ, ॱ) == 442) {
                o_anc.ˋ(ॱ + 4);
                long ˋ2 = ˋ(o_anc);
                if (ˋ2 != -9223372036854775807L) {
                    return ˋ2;
                }
            }
        }
        return -9223372036854775807L;
    }

    private int ˎ(byte[] bArr, int i) {
        return ((((bArr[i] & 255) << 24) | ((bArr[i + 1] & 255) << 16)) | ((bArr[i + 2] & 255) << 8)) | (bArr[i + 3] & 255);
    }

    private static boolean ॱ(byte[] bArr) {
        boolean z = true;
        if ((bArr[0] & 196) != 68 || (bArr[2] & 4) != 4 || (bArr[4] & 4) != 4 || (bArr[5] & 1) != 1) {
            return false;
        }
        if ((bArr[8] & 3) != 3) {
            z = false;
        }
        return z;
    }

    private static long ˎ(byte[] bArr) {
        return ((((((((((long) bArr[0]) & 56) >> 3) << 30) | ((((long) bArr[0]) & 3) << 28)) | ((((long) bArr[1]) & 255) << 20)) | (((((long) bArr[2]) & 248) >> 3) << 15)) | ((((long) bArr[2]) & 3) << 13)) | ((((long) bArr[3]) & 255) << 5)) | ((((long) bArr[4]) & 248) >> 3);
    }
}
